package com.myphoto.base.config.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.myphoto.base.annotation.DevProfile;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@EnableOpenApi  //swagger 3
@EnableKnife4j  //Knife4j
@Configuration
@DevProfile
public class SwaggerConfigDev {
    @Bean
    public Docket createRestApiForAll() {
        return new Docket(DocumentationType.OAS_30)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.myphoto"))
                .paths(PathSelectors.any()).build().groupName("所有API").pathMapping("/");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("相片存储平台")
                .termsOfServiceUrl("")
                .contact(new Contact("方安伦","https://gitee.com/allen356/","byzxedu@163.com"))
                .description("相片存储平台，私人使用")
                .version("1.0")
                .build();
    }

    /***********************************根据包路径进行分组************************************/

    //日志管理
    @Bean
    public Docket createRestApiForLog() {
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.myphoto.base.log.controller"))
                .paths(PathSelectors.any()).build().groupName("日志管理").pathMapping("/");
    }

    //相片管理
    @Bean
    public Docket createRestApiForPhoto() {
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.myphoto.business.photo.controller"))
                .paths(PathSelectors.any()).build().groupName("相片管理").pathMapping("/");
    }
}
